package edu.unh.sustain;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class Route4Activity extends TabActivity {

	String timeframe = "weekdays";
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.route4);
	    int tab = 0;
	    
	    if( savedInstanceState != null )
	    {
	    	timeframe = (String) savedInstanceState.getSerializable("timeframe");
	    }
	    else
	    {
	    	Bundle extras = getIntent().getExtras();
	    	
	    	if( extras != null )
	    	{
	    		timeframe = extras.getString("timeframe");
	    		tab = extras.getInt("tab");
	    	}
	    }
	    
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Reusable TabSpec for each tab
	    Intent intent;  // Reusable Intent for each tab

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    intent = new Intent().setClass(this, Route4aActivity.class);
	    intent.putExtra( "timeframe", timeframe );

	    // Initialize a TabSpec for each tab and add it to the TabHost
	    spec = tabHost.newTabSpec("4a").setIndicator("Route 4A",
	                      null)
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    // Do the same for the other tabs
	    intent = new Intent().setClass(this, Route4bActivity.class);
	    intent.putExtra( "timeframe", timeframe );
	    spec = tabHost.newTabSpec("4b").setIndicator("Route 4B",
	                      null)
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    tabHost.setCurrentTab(tab);
	    
	}
	
	/**
	 * Saves the state of the screen.  This is called on orientation changes. 
	 */
	@Override
	public void onSaveInstanceState(Bundle savedInstanceState)
	{
		  savedInstanceState.putString("timeframe", timeframe);
		  super.onSaveInstanceState(savedInstanceState);
	}
	
	/**
	 * Restore IU to original state.
	 */
	@Override
	public void onRestoreInstanceState(Bundle savedInstanceState)
	{
		super.onRestoreInstanceState(savedInstanceState);
		//Restore UI state from the savedInstanceState.
		// This bundle has also been passed to onCreate.
		timeframe = savedInstanceState.getString("timeframe");
	}
}
